import React from "react";

var RankingBasic = {
    createRank: function (pdata, sort) {
        var unitProps = this.props.unit;
        var tbody = new Array();
        var data = new Array();
        $.extend(true,data , pdata);
        if (data != null && data.length > 0) {
            data.forEach(function (val, key, array) {
                var unit = unitProps;
                if(unit == "%"){
                    val.sj =  _.round(val.sj * 100, 2);
                }
                if(unit == "‰"){
                    val.sj = _.round(val.sj * 1000, 2);
                }
                if(Math.abs(val.sj) / 10000/10000 > 1){
                    val.sj = _.round(val.sj /10000/10000, 2);
                    unit =  "亿" + unit;
                }else if(Math.abs(val.sj) / 10000 > 1){
                    val.sj = _.round(val.sj /10000, 2);;
                    unit = "万" + unit;
                }
                tbody.push(
                    <tr key={key} className={"n" + (key+1)}>
                        <td className="title">
                            <div className={key < 3 ? "num num123" : "num"}>{key + 1}</div>
                            {val.mc}</td>
                        <td className="value">
                            <div className="progress">
                                <div
                                    className={"progress-bar" + (val.sj < 0 ? " minus" : "") + " width" + (sort === true ? 100 - key * 5 : 50 + key * 5)}
                                    role="progressbar" aria-valuenow="90" aria-valuemin="0"
                                    aria-valuemax="100">{val.sj + unit}</div>
                            </div>
                        </td>
                    </tr>
                )
            });
        }
        return tbody;
    }
};

var Ranking = React.createClass({
    mixins: [RankingBasic],
    render: function() {

        var rdata1 = this.props.rdata1;
        var tbody1 = this.createRank(rdata1, true);
        return (


            <div className="btm_main">
                <div className="title_main">
                    <div className="sort_type">
                        <span className={this.props.params.yyb_lx == "2" ? "first now" : "first"} id="rank2" onTouchTap={this.props.onSelectRank}>分公司</span>
                        <span className={this.props.params.yyb_lx == "3" ? "second now" : "second"} id="rank3" onTouchTap={this.props.onSelectRank}>营业部</span>
                    </div>
                    <div className="title">
                        <i className="icon-flag"></i>
                        <span>{this.props.title}</span>
                    </div>
                </div>
				<span id="barprogress">
					<table>
                        <tbody>
                        {tbody1}
                        </tbody>
                    </table>
				</span>
            </div>
        );
    }
});

export { Ranking };